package com.chuangke.common.express.function.date;

import java.util.Date;
import java.util.Map;

import com.chuangke.common.utils.DateUtils;
import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.function.FunctionUtils;
import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorString;

public class DateMonthFunction extends AbstractFunction {
	
	
    private static final long serialVersionUID = 1879134439604811158L;


	@Override
	public AviatorObject call(Map<String, Object> env) {
		Date date = new Date();
		return new AviatorString(DateUtils.getDate(date, "yyyyMM"));
	}

	@Override
	public AviatorObject call(Map<String, Object> env, AviatorObject arg1) {
		Date date = (Date) arg1.getValue(env);
		return new AviatorString(DateUtils.getDate(date, "yyyyMM"));
	}
	
	@Override
	public AviatorObject call(Map<String, Object> env, AviatorObject arg1,AviatorObject arg2) {
		Date date = DateUtils.getDate(FunctionUtils.getStringValue(arg1, env), FunctionUtils.getStringValue(arg2, env));
		return new AviatorString(DateUtils.getDate(date, "yyyyMM"));
	}


	@Override
	public String getName() {
		return "date.month";
	}

}
